package com.example.controller;

import com.example.service.HazelcastService;
import com.hazelcast.cp.lock.FencedLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestLockController {

    Logger logger = LoggerFactory.getLogger(getClass());

    public static final String LOCK = "LOCK";

    @Resource
    private HazelcastService hazelcastService;

    @RequestMapping("getLock")
    public void getLock() {
        FencedLock lock = hazelcastService.getLock(LOCK);
        lock.lock();
        System.out.println("业务操作 业务操作 业务操作");
        lock.unlock();
    }
}
